var a, t = require("../../../mymap/qqmap-wx-jssdk.min.js"), e = getApp();

Page({
    data: {
        city: "",
        suggestion: [],
        suggestion1: [],
        suggestionshow1: !1,
        suggestionshow: !1,
        address_detail: "",
        address_latitude: "",
        address_longitude: "",
        mksData: [],
        markers: [],
        mapmessageData: {
            title: "",
            message: "",
            latitude: "",
            longitude: "",
            city: ""
        },
        scaleData: 16,
        mapshow: !1
    },
    onLoad: function(s) {
        var i = this;
        s.id && this.setData({
            id: s.id
        }), e.globalData.qqmapkey ? (a = new t({
            key: e.globalData.qqmapkey
        }), s.tag && this.setData({
            tag: s.tag
        }), s.city && this.setData({
            city: s.city
        }), this._getLocation()) : e._getTemplate().then(function(d) {
            a = new t({
                key: e.globalData.qqmapkey
            }), s.tag && i.setData({
                tag: s.tag
            }), s.city && i.setData({
                city: s.city
            }), i._getLocation();
        });
    },
    _getLocation: function() {
        var t = this;
        a.getSuggestion({
            keyword: t.data.city,
            region: t.data.city,
            sig: e.globalData.qqmapsig,
            success: function(a) {
                for (var e = [], s = 0; s < a.data.length; s++) e.push({
                    title: a.data[s].title,
                    id: a.data[s].id,
                    addr: a.data[s].address,
                    city: a.data[s].city,
                    district: a.data[s].district,
                    latitude: a.data[s].location.lat,
                    longitude: a.data[s].location.lng
                });
                t.setData({
                    suggestion1: e,
                    suggestionshow1: !0
                });
            },
            fail: function(a) {
                console.error(a);
            },
            complete: function(a) {}
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    goback: function() {
        wx.navigateBack({
            delta: 1
        }), this.setData({
            mapshow: !1,
            address_detail: "",
            suggestionshow1: !0
        });
    },
    searchconfirmbtn: function(a) {
        var t = a.detail.value;
        this.addressinp(t);
    },
    addressinpbtn: function(a) {
        var t = a.detail.value;
        this.addressinp(t);
    },
    addressinp: function(t) {
        var s = this;
        t ? a.getSuggestion({
            keyword: t,
            region: s.data.city,
            sig: e.globalData.qqmapsig,
            success: function(a) {
                for (var t = [], e = 0; e < a.data.length; e++) t.push({
                    title: a.data[e].title,
                    id: a.data[e].id,
                    addr: a.data[e].address,
                    city: a.data[e].city,
                    district: a.data[e].district,
                    latitude: a.data[e].location.lat,
                    longitude: a.data[e].location.lng
                });
                s.setData({
                    suggestion: t,
                    suggestionshow: !0
                });
            },
            fail: function(a) {
                console.error(a);
            },
            complete: function(a) {}
        }) : this.setData({
            suggestionshow: !1
        });
    },
    backfill1: function(a) {
        console.log(a.currentTarget.id, "e.currentTarget.id");
        for (var t = a.currentTarget.id, e = 0; e < this.data.suggestion1.length; e++) e == t && (this.setData({
            address_detail: this.data.suggestion1[e].title,
            address_latitude: this.data.suggestion1[e].latitude,
            address_longitude: this.data.suggestion1[e].longitude,
            "mapmessageData.title": this.data.suggestion1[e].title,
            "mapmessageData.message": this.data.suggestion1[e].addr,
            "mapmessageData.latitude": this.data.suggestion1[e].latitude,
            "mapmessageData.longitude": this.data.suggestion1[e].longitude,
            "mapmessageData.city": this.data.suggestion1[e].city,
            suggestionshow1: !1,
            mapshow: !0
        }), this.nearby_search());
    },
    backfill: function(a) {
        console.log(a.currentTarget.id, "e.currentTarget.id");
        for (var t = a.currentTarget.id, e = 0; e < this.data.suggestion.length; e++) e == t && (this.setData({
            address_detail: this.data.suggestion[e].title,
            address_latitude: this.data.suggestion[e].latitude,
            address_longitude: this.data.suggestion[e].longitude,
            "mapmessageData.title": this.data.suggestion[e].title,
            "mapmessageData.message": this.data.suggestion[e].addr,
            "mapmessageData.latitude": this.data.suggestion[e].latitude,
            "mapmessageData.longitude": this.data.suggestion[e].longitude,
            "mapmessageData.city": this.data.suggestion[e].city,
            suggestionshow: !1,
            mapshow: !0
        }), this.nearby_search());
    },
    nearby_search: function() {
        var t = this;
        a.search({
            keyword: this.data.address_detail,
            location: {
                latitude: this.data.address_latitude,
                longitude: this.data.address_longitude
            },
            sig: e.globalData.qqmapsig,
            success: function(a) {
                for (var e = [], s = [], i = 0; i < a.data.length; i++) e.push({
                    title: a.data[i].title,
                    id: a.data[i].id,
                    latitude: a.data[i].location.lat,
                    longitude: a.data[i].location.lng,
                    iconPath: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
                    width: 20,
                    height: 25,
                    callout: {
                        padding: "10rpx",
                        borderRadius: "5rpx",
                        content: a.data[i].title
                    }
                }), s.push({
                    address: a.data[i].address,
                    title: a.data[i].title,
                    latitude: a.data[i].location.lat,
                    longitude: a.data[i].location.lng,
                    id: a.data[i].id,
                    city: a.data[i].ad_info.city ? a.data[i].ad_info.city : a.res.data[i].ad_info.province
                });
                t.setData({
                    markers: e,
                    mksData: s
                });
            },
            fail: function(a) {
                console.log(a);
            },
            complete: function(a) {
                console.log(a);
            }
        });
    },
    getmarkertap: function(a) {
        for (var t = a.markerId, e = 0; e < this.data.mksData.length; e++) {
            t == this.data.mksData[e].id && this.setData({
                "mapmessageData.title": this.data.mksData[e].title,
                "mapmessageData.message": this.data.mksData[e].address,
                "mapmessageData.latitude": this.data.mksData[e].latitude,
                "mapmessageData.longitude": this.data.mksData[e].longitude,
                "mapmessageData.city": this.data.mksData[e].city
            });
        }
    },
    addbtn: function() {
        var a = wx.createMapContext("myMap"), t = this;
        a.getScale({
            success: function(a) {
                var e = a.scale;
                t.setData({
                    scaleData: e + 1
                });
            }
        });
    },
    minusbtn: function() {
        var a = wx.createMapContext("myMap"), t = this;
        a.getScale({
            success: function(a) {
                var e = a.scale;
                t.setData({
                    scaleData: e - 1
                });
            }
        });
    },
    buttonbtn: function() {
        if ("activityHome" == this.data.tag || "activitySearch" == this.data.tag || "activitySort" == this.data.tag) wx.setStorage({
            key: "address-point",
            data: {
                point: {
                    lat: this.data.mapmessageData.latitude,
                    lng: this.data.mapmessageData.longitude
                },
                city: this.data.mapmessageData.city
            }
        }); else if ("storeConsume" == this.data.tag) wx.setStorage({
            key: "address-point",
            data: {
                point: {
                    lat: this.data.mapmessageData.latitude,
                    lng: this.data.mapmessageData.longitude
                },
                city: this.data.mapmessageData.message
            }
        }); else {
            if (this.data.tag && -1 !== this.data.tag.indexOf("project_verification")) {
                switch (wx.setStorage({
                    key: "address-point",
                    data: {
                        point: {
                            lat: this.data.mapmessageData.latitude,
                            lng: this.data.mapmessageData.longitude
                        },
                        city: this.data.mapmessageData.message
                    }
                }), this.data.tag) {
                  case "project_verification/MyProject":
                    wx.reLaunch({
                        url: "/packageH/project_verification/MyProject/MyProject?location_change=1&Location=" + JSON.stringify(this.data.mapmessageData)
                    });
                    break;

                  case "project_verification/VerificationProjectList":
                    wx.reLaunch({
                        url: "/packageH/project_verification/VerificationProjectList/VerificationProjectList?location_change=1"
                    });
                }
                return;
            }
            wx.setStorage({
                key: "address-point",
                data: {
                    point: {
                        lat: this.data.mapmessageData.latitude,
                        lng: this.data.mapmessageData.longitude
                    },
                    city: this.data.mapmessageData.city
                }
            });
        }
        if (wx.setStorage({
            key: "address-status",
            data: "1"
        }), "hotel" == this.data.tag) wx.reLaunch({
            url: "/packageC/hotel/HotelIndex/HotelIndex?addressData=" + JSON.stringify(this.data.mapmessageData)
        }); else if ("home" == this.data.tag) wx.reLaunch({
            url: "/packageG/index/index?addressData=" + JSON.stringify(this.data.mapmessageData)
        }); else if ("diy" == this.data.tag) {
            var a = wx.getStorageSync("diyurl");
            wx.reLaunch({
                url: a
            });
        } else if ("easyRefuel" == this.data.tag) wx.reLaunch({
            url: "/packageD/easyRefuel/easyRefuel"
        }); else if ("activityHome" == this.data.tag) wx.reLaunch({
            url: "/packageC/Myshaky/activityHome/activityHome?addressData=" + JSON.stringify(this.data.mapmessageData)
        }); else if ("activitySearch" == this.data.tag) wx.reLaunch({
            url: "/packageC/Myshaky/activityHome/activityHome?addressData=" + JSON.stringify(this.data.mapmessageData)
        }); else if ("activitySort" == this.data.tag) wx.navigateBack({
            delta: 2
        }); else if ("appointment" == this.data.tag) wx.reLaunch({
            url: "/packageE/appointment/appointment_index"
        }); else if ("communityStore" == this.data.tag) wx.reLaunch({
            url: "/packageH/o2o/communityStore/communityStore"
        }); else if ("communityStoreDetails" == this.data.tag) {
            var t = wx.getStorageSync("communityStoreDetailsUrl");
            wx.reLaunch({
                url: t
            });
        } else "storeConsume" == this.data.tag ? wx.reLaunch({
            url: "/packageH/o2o/storeConsumeIndex/storeConsumeIndex?addressData=" + JSON.stringify(this.data.mapmessageData) + "&id=" + this.data.id
        }) : "tagCloud" == this.data.tag ? wx.navigateBack({
            delta: 2
        }) : wx.reLaunch({
            url: "/packageC/o2o/o2oHome/o2oHome?addressData=" + JSON.stringify(this.data.mapmessageData)
        });
    }
});